<?php
/*
 * @FilePath: SupplyBanner.php
 * @Author: 谭贤伟
 * @Date: 2023-04-01 14:10:02
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-04-02 18:53:32
 * @Descripttion: 
 */
/*
 * @ControllerAnnotation(title="横幅广告模型")
 */

namespace app\admin\model;

use app\common\model\SupplyModel;
use think\facade\Cache;

class SupplyBanner extends SupplyModel
{
    public static function onAfterUpdate($banner)
    {
        $banner = Cache::get('banner')->where('id', $banner->id);
        if ($banner) {
            $banners = self::where('status', 1)
                ->where('delete_time', null)
                ->limit(5)
                ->select();

            Cache::delete('banner');
            Cache::set('banner', $banners);
        }
    }
    public static function onBeforeDelete($banner)
    {
        $banner = Cache::get('banner')->where('id', $banner->id);
        if ($banner) {
            $banners = self::where('status', 1)
                ->where('delete_time', null)
                ->limit(5)
                ->select();

            Cache::delete('banner');
            Cache::set('banner', $banners);
        }
    }
    public static function onAfterInsert($banner)
    {
        $banners = self::where('status', 1)
            ->where('delete_time', null)
            ->limit(5)
            ->select();

        Cache::delete('banner');
        Cache::set('banner', $banners);
    }
}
